package com.qckj.amz.controller;

import com.qckj.amz.domain.ProductAmzUploadTask;
import com.qckj.amz.service.IProductAmzUploadTaskService;
import com.qckj.common.annotation.Log;
import com.qckj.common.core.controller.BaseController;
import com.qckj.common.core.domain.AjaxResult;
import com.qckj.common.core.page.TableDataInfo;
import com.qckj.common.enums.BusinessType;
import com.qckj.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 上传任务Controller
 *
 * @author luchuan
 * @since 1.0 2022-11-25
 */
@RestController
@RequestMapping("/amz/productAmzUploadTask")
public class ProductAmzUploadTaskController extends BaseController {
    @Autowired
    private IProductAmzUploadTaskService productAmzUploadTaskService;

    /**
     * 查询上传任务列表
     */
    @PreAuthorize("@ss.hasPermi('amz:productAmzUploadTask:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProductAmzUploadTask productAmzUploadTask) {
        Page<ProductAmzUploadTask> page = productAmzUploadTaskService.findProductAmzUploadTaskPage(productAmzUploadTask);
        return getDataTable(page);
    }

    /**
     * 导出上传任务列表
     */
    @PreAuthorize("@ss.hasPermi('amz:productAmzUploadTask:export')")
    @Log(title = "上传任务", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ProductAmzUploadTask productAmzUploadTask) {
        List<ProductAmzUploadTask> list = productAmzUploadTaskService.findProductAmzUploadTaskList(productAmzUploadTask);
        ExcelUtil<ProductAmzUploadTask> util = new ExcelUtil<>(ProductAmzUploadTask.class);
        return util.exportExcel(list, "productAmzUploadTask");
    }

    /**
     * 获取上传任务详细信息
     */
    @PreAuthorize("@ss.hasPermi('amz:productAmzUploadTask:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(productAmzUploadTaskService.findById(id));
    }

    /**
     * 新增上传任务
     */
    @PreAuthorize("@ss.hasPermi('amz:productAmzUploadTask:add')")
    @Log(title = "上传任务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProductAmzUploadTask productAmzUploadTask) {
        productAmzUploadTaskService.save(productAmzUploadTask);
        return AjaxResult.success();
    }

    /**
     * 修改上传任务
     */
    @PreAuthorize("@ss.hasPermi('amz:productAmzUploadTask:edit')")
    @Log(title = "上传任务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductAmzUploadTask productAmzUploadTask) {
        productAmzUploadTaskService.save(productAmzUploadTask);
        return AjaxResult.success();
    }

    /**
     * 删除上传任务
     */
    @PreAuthorize("@ss.hasPermi('amz:productAmzUploadTask:remove')")
    @Log(title = "上传任务", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        productAmzUploadTaskService.deleteByIds(Arrays.asList(ids));
        return AjaxResult.success();
    }

    /**
     * 重新上传
     * @param ids
     * @return
     */
    @PreAuthorize("@ss.hasPermi('amz:productAmzUploadTask:uploadTask')")
    @PostMapping("/uploadTask")
    public AjaxResult uploadTask(@RequestParam(name = "ids") List<Long> ids) {
        AjaxResult res = productAmzUploadTaskService.uploadTask(ids);
        return res;
    }

    /**
     * 获取上传报告
     * @param ids
     * @return
     */
    @PreAuthorize("@ss.hasPermi('amz:productAmzUploadTask:getUploadFeedsReport')")
    @PostMapping("/getUploadFeedsReport")
    public AjaxResult getUploadFeedsReport(@RequestParam(name = "ids") List<Long> ids) {
        AjaxResult res = productAmzUploadTaskService.getUploadFeedsReport(ids);
        return res;
    }


}
